import React, { useState } from 'react';
import { Table,Pagination, } from 'antd';
import examinationColumn from '../../pages/Home/Examination/tableColums';



function ExaminationList({
  updateExamination,
  deleExamination,
  role,
  examination
}) {
  const {stuColumns,teaColumns}=examinationColumn(updateExamination,deleExamination)
  const column = role?.fd_type === "student" ? stuColumns : role?.fd_type === "teacher" ? teaColumns: []

  // 分页
  const [page, setPage] = useState(1);
  const pageSize = 11;
  const start = (page - 1) * pageSize;
  const end = start + pageSize;
  const paginatedData = examination?.slice(start, end).map((item,index)=>{
    return {...item,index:index +1 +start}
  })

  const onPageChange = (page, pageSize) => {
    setPage(page);
  };

  return (
    <>
      <Table
          bordered
          columns={column}
          dataSource={paginatedData}
          pagination={false}
          size="small"
          rowKey={"index"}
          scroll={{ x: 'max-content' }}
        />
      <Pagination
          current={page}
          pageSize={pageSize}
          total={examination?.length}
          onChange={onPageChange}
          showSizeChanger={false}
          style={{ marginTop: '16px', textAlign: "right" }}
        />
    </>
  );
}

export default ExaminationList;
